﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Kopain
{

    /// <summary>This class contains common methods, functions, classes, constants, whatever.
    /// </summary>
    class Common
    {
        /// <summary>This method returns true if some specific buttons were pressed.
        /// Or rather: it is called from a KeyDown event and returns if some specific buttons were pressed.
        /// </summary>
        /// <param name="inputKeys">The keys the user pressed.  Usually KeyEventArgs.KeyData.</param>
        /// <param name="checkKeys">The keys we are looking for.  E.g.: Keys.Control | Keys.Up</param>
        /// <param name="only">Set to true if the checkKeys and nothing else is pressed.  When set to false the method
        /// returns true if the checkKeys are among the buttons pressed.</param>
        /// <returns></returns>
        /// <example>
        /// The user presses shift-ctrl-up
        /// CheckKeys( e.KeyData, Keys.Control | Keys.Up, false ) => True.
        /// CheckKeys( e.KeyData, Keys.Control | Keys.Up, true ) => False.
        /// </example>
        internal static bool CheckKeys(Keys inputKeys, Keys checkKeys, bool only)
        {
            if (only)
            {
                if (inputKeys == checkKeys)
                {
                    return true;
                }
            }
            else
            {
                if ((inputKeys & checkKeys) == checkKeys)
                {
                    return true;
                }
            }
            return false;
        }


    }

}
